package com.guaju.yueshangLife.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.bean.CartGoods;
import com.guaju.yueshangLife.bean.MeOrder;

import java.util.ArrayList;
import java.util.List;

public class OrderGoodsDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context context;
    ArrayList<CartGoods> list;
    private int status = 1;


    Activity activity;
    private final LayoutInflater layoutInflater;
    private View view;

    public OrderGoodsDetailAdapter(Context context, ArrayList<CartGoods>  list) {
        this.context = context;
        this.list = list;
        activity = (Activity) context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {
        View view = layoutInflater.inflate(R.layout.item_order_goods_detail, parent, false);
        InnerHolder innerHolder = new InnerHolder(view);
        return innerHolder;

    }

    //绑定
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        InnerHolder innerHolder = (InnerHolder) holder;
        innerHolder.setContent(list.get(position));
    }

    //有多少个item？
    @Override
    public int getItemCount() {
        return list.size();
    }


    public interface OnItemClickListener {
        void onItemClick();

        void onItemLongClick(View v);
    }

    public OrderGoodsDetailAdapter.OnItemClickListener mOnItemClickListener;//第二步：声明自定义的接口

    //第三步：定义方法并暴露给外面的调用者
    public void setOnItemClickListener(OrderGoodsDetailAdapter.OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    class InnerHolder extends RecyclerView.ViewHolder {
        SimpleDraweeView sdv_inner;
        TextView tv_inner_title, tv_inner_attr, tv_inner_num, tv_inner_price,tv_delivery_method;

        public InnerHolder(View itemView) {
            super(itemView);
            sdv_inner = itemView.findViewById(R.id.sdv_inner);
            tv_inner_attr = itemView.findViewById(R.id.tv_inner_attr);
            tv_inner_title = itemView.findViewById(R.id.tv_inner_title);
            tv_inner_num = itemView.findViewById(R.id.tv_inner_num);
            tv_inner_price = itemView.findViewById(R.id.tv_inner_price);
            tv_delivery_method = itemView.findViewById(R.id.tv_delivery_method);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onItemClick();
                }
            });
        }

        public void setContent(CartGoods bean ) {
            sdv_inner.setImageURI(bean.getImageUrl());
            String attribute = bean.getAttribute();
            tv_inner_attr.setText(attribute);
            tv_inner_num.setText("x " + bean.getCount());
            tv_inner_title.setText(bean.getTitle());
            tv_inner_price.setText(bean.getPrice());
            tv_delivery_method.setText(bean.getDelivery());


        }

    }


}
